<?php if( empty( $_SESSION )){session_start();}header("Content-Type: text/html; charset=utf-8",true);
include_once("../../includes/restrito.php");include_once("../models/cls.edicao.php");include_once("../models/cls.pagina.indice.php");include_once("../models/cls.pagina.php");
$oSumario = new pagina_indice();$oPagina  = new pagina();$oEdicao  = new edicao();
if( ! empty ( $_GET["id"] ) && ! empty( $_GET["nome"] ) ){
	$_SESSION["id_edicao"]   = $_GET["id"];
	$_SESSION["nome_edicao"] = $_GET["nome"];
}
else
{
	header("location:frm.edicao.php");
}

if( ! empty( $_GET["acao"] ) )
{
	if( $_GET["acao"] == 'up' )
	{
		$add = $oSumario->ordem( 'up' , $_GET["id"] );
		if( $add == 1 )
		{
			header( "location:../views/frm.edicao.controle.php?id=".$_SESSION["id_edicao"]."&nome=".$_SESSION["nome_edicao"] );
		}
	}
	elseif( $_GET["acao"] == 'dowm' )
	{
		$add = $oSumario->ordem( 'dowm' , $_GET["id"] );
		if( $add == 1 )
		{
			header( "location:../views/frm.edicao.controle.php?id=".$_SESSION["id_edicao"]."&nome=".$_SESSION["nome_edicao"] );
		}
	}	elseif( $_GET["acao"] == 'desativar' )	{		$add = $oSumario->capa( $_GET["id"] , 'out' );		if( $add > 0 )		{			header( "location:../views/frm.edicao.controle.php?id=".$_SESSION["id_edicao"]."&nome=".$_SESSION["nome_edicao"] );		}	}	else	{		$add = $oSumario->capa( $_GET["id"] , 'in' );		if( $add > 0 )		{			header( "location:../views/frm.edicao.controle.php?id=".$_SESSION["id_edicao"]."&nome=".$_SESSION["nome_edicao"] );		}	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>EDIÇÃO CONTROLE</title></head><link rel="stylesheet" type="text/css" href="../../includes/sistema.css"><link type="text/css" media="screen" rel="stylesheet" href="../../includes/colorbox.css" /><!--[if IE]><link type="text/css" media="screen" rel="stylesheet" href="../../includes/colorbox-ie.css" title="example" /><![endif]--><script src="../../includes/jquery-1.3.2.min.js"></script><script src="../../includes/jquery.colorbox.js" type="text/javascript"></script><script src="../../includes/main.js" type="text/javascript"></script><script>$(function(){	$(".preview").colorbox({ width:"90%", height:"90%", iframe:true });});function _excluir( id , quem ){	if( quem == 1 )	{		if( confirm("Por favor, confirme há remoção do sumário!") )		{			window.location.href="frm.pagina.indice.php?id_delete=" + id + "&acao=excluir";		}	}	else	{		if( confirm("Por favor, confirme há remoção da página!") )		{			window.location.href="frm.pagina.php?id_delete=" + id + "&acao=excluir";		}	}}</script><style>#divRevista{	border:#CCC solid 1px;	width:20%;	padding:5px;}#divRevista:hover{	background-color:#E6E6E6;	border:#666 solid 1px;	width:20%;	padding:5px;}</style><body>  <table width="98%" border="0" align="center" cellpadding="0" cellspacing="5">    <tr>      <td colspan="2" align="center">      <div id="edicao">			<h1>Edição:			<?php					$aEdicao = $oEdicao->select_edicao_controle( $_SESSION["id_edicao"] );			foreach($aEdicao as $sItem)            {                echo $sItem["nome"];                				$especial          = $sItem["especial"]; 				$publicar          = $sItem["publicar"];				$idioma_sigla      = $sItem["sigla"];				$ano               = $sItem["ano"];				$data              = $oEdicao->formatar_data( $sItem["data"] , "get" );            }            ?>            </h1>			<table width="100%" cellpadding="5" cellspacing="2" border="0" align="center">           	  <tr>                	<td width="16%" height="75" align="center">					<?php 						if( $especial == 1)						{							echo "<img src='../imagens/ativar.grande.png' border='0'><br />Edição Especial";						}						else						{							echo "<img src='../imagens/ativar.grande.out.png' border='0'><br />Edição Mensal";						}							?>                    </td>                    <td width="16%" height="75" align="center">					<?php						if( $publicar == 1)						{							echo "<img src='../imagens/planeta.grande.png' border='0'><br />Publicada";						}						else						{							echo "<img src='../imagens/planeta.grande.out.png' border='0'><br />Não publicada";						}					?>
                  </td>
                    <td width="16%" height="75" align="center">
					<?php
						echo "<img src='../imagens/". strtolower($idioma_sigla) .".png' border='0'><br />Idioma";
					?>
                  </td>
                  <td width="16%" height="75" align="center"><?php echo "<img src='../imagens/papel.png' border='0'><br />Ano nº: " . $ano; ?></td>
                  <td width="16%" height="75" align="center"><?php echo "<img src='../imagens/data.png' border='0'><br />" . $data; ?></td>                  <td width="16%" align="center">                  <a href="frm.edicao.imagem.php?id=<?php echo $_SESSION["id_edicao"]; ?>&data=<?php echo $data; ?>" title="Imagem desta Edição">
                  <div id="divRevista">
                  <img src='../imagens/revista.png' border='0'><br />
                  Imagem
                  </div>
                  </a>
                  </td>
                </tr>
            </table>
      </div>
    </td>
    </tr>
    <tr>
    	<td width="50%" valign="top">
            <div id="sumario">
            	<h2><a href="frm.pagina.indice.php?id_edicao=<?php echo $_SESSION["id_edicao"]; ?>">
                <img title="Novo índice do sumário" src="../imagens/novo.grande.png" border="0" align="absmiddle" />                </a>                Novo índice do sumário                </h2>
            	<?php            	$cor=true;
                $aSumario = $oSumario->select_sumario( $_SESSION["id_edicao"] , 0 );                
				if( ! empty( $aSumario ) )
				{
					echo '<table width="98%">';
					echo '<th align="left">SUMÁRIO SUPERIOR</th>';
					echo '<th align="center">ORDEM</th>';
					echo '<th align="center">EDITAR</th>';
					echo '<th align="center">EXCLUIR</th>';
					foreach( $aSumario as $sItem )
					{						if( $cor ){$tdcor = "#F4F4F4";$cor = false;}else{$tdcor = "#FFFFFF";$cor = true;}						echo '<tr bgcolor="'. $tdcor .'">';
						$ordem = ( $sItem["ordem"] < 10 )? "0" . $sItem["ordem"] : $sItem["ordem"];
						echo '<td>' . $ordem . ' - ' . $sItem["titulo"] . '</td>';
						echo '<td width="5%" align="center"><div style="padding:3px;"><a href="frm.edicao.controle.php?id=' . $sItem["id"] . '&acao=down"><img src="../imagens/icon.up.gif" border="0"></a><br><a href="frm.edicao.controle.php?id=' . $sItem["id"] . '&acao=up"></div><div style="padding:3px;"><img src="../imagens/icon.down.gif" border="0"></a></div></td>';
						echo '<td width="5%" align="center"><a href="frm.pagina.indice.php?id=' . $sItem["id"] . '&acao=editar"><img src="../imagens/editar.png" title="Editar: '.$sItem["titulo"].'" border="0"></a></td>';
						echo '<td width="5%" align="center"><a href="javascript:_excluir(' . $sItem["id"] . ',1);"><img src="../imagens/excluir.png" title="Excluir: '.$sItem["titulo"].'" border="0"></a></td>';						echo '</tr>';					}
					echo '</table>';
				}
				else
				{
					echo "Sumário vazio";
				}								$aSumario = $oSumario->select_sumario( $_SESSION["id_edicao"] , 1 );				if( ! empty( $aSumario ) )				{					echo '<table width="98%">';					echo '<th align="left">SUMÁRIO INFERIOR</th>';					echo '<th align="center">ORDEM</th>';					echo '<th align="center">EDITAR</th>';					echo '<th align="center">EXCLUIR</th>';					foreach( $aSumario as $sItem )					{						if( $cor ){$tdcor = "#F4F4F4";$cor = false;}else{$tdcor = "#FFFFFF";$cor = true;}						echo '<tr bgcolor="'. $tdcor .'">';						$ordem = ( $sItem["ordem"] < 10 )? "0" . $sItem["ordem"] : $sItem["ordem"];						echo '<td>' . $ordem . ' - ' . $sItem["titulo"] . '</td>';						echo '<td width="5%" align="center"><div style="padding:3px;"><a href="frm.edicao.controle.php?id=' . $sItem["id"] . '&acao=down"><img src="../imagens/icon.up.gif" border="0"></a><br><a href="frm.edicao.controle.php?id=' . $sItem["id"] . '&acao=up"></div><div style="padding:3px;"><img src="../imagens/icon.down.gif" border="0"></a></div></td>';						echo '<td width="5%" align="center"><a href="frm.pagina.indice.php?id=' . $sItem["id"] . '&acao=editar"><img src="../imagens/editar.png" title="Editar: '.$sItem["titulo"].'" border="0"></a></td>';						echo '<td width="5%" align="center"><a href="javascript:_excluir(' . $sItem["id"] . ',1);"><img src="../imagens/excluir.png" title="Excluir: '.$sItem["titulo"].'" border="0"></a></td>';						echo '</tr>';					}					echo '</table>';				}				else				{					echo "Sumário vazio";				}
				?>
            </div>
        </td>
    	<td width="50%" valign="top">
          <div id="paginas">
            	<h2><a href="frm.pagina.php?id_edicao=<?php echo $_SESSION["id_edicao"]; ?>">
                <img title="Nova página" src="../imagens/novo.grande.png" border="0" align="absmiddle" />                </a>                Nova página                </h2>
            	<?php				$cor=true;            
                $aPagina = $oPagina->select_pagina( $_SESSION["id_edicao"] );
				if( ! empty(  $aPagina ) )
				{
					echo '<table width="98%">';
					echo '<th align="left">TÍTULO</th>';
					echo '<th align="center">&nbsp;CAPA&nbsp;</th>';
					echo '<th align="center">EDITAR</th>';
					echo '<th align="center">EXCLUIR</th>';
					foreach( $aPagina as $sItem ) // VARRE A LISTA E IMPRIME OS ÍNDICES DA COLEÇÃO
					{
						// ALTERNA AS CORES DA LINHA DA TABELA A CADA REGISTRO IMPRESSO
						if($cor)
						{
							$tdcor = "#F4F4F4"; //CINZA CLARO
							$cor=false;
						}
						else						{
							$tdcor = "#FFFFFF"; //BRANCO
							$cor = true;
						}
						echo '<tr bgcolor="'. $tdcor .'">';
						//echo '<td>' . $sItem["titulo"] . '</td>';
						echo '<td><a class="preview" href="../../pagina/?id=' . $sItem["id_pagina_indice"] . '" target="_blank">' . $sItem["titulo"] . '</a></td>';
						echo '<td width="5%" align="center">' . $oPagina->icone_capa( $sItem["capa"] , $sItem["id"] ) . '</td>';
						echo '<td width="5%" align="center"><div style="padding:3px;"><a href="frm.pagina.php?id=' . $sItem["id"] . '&acao=editar"><img src="../imagens/editar.png" title="Editar: '.$sItem["titulo"].'" border="0"></a></div></td>';
						echo '<td width="5%" align="center"><a href="javascript:_excluir(' . $sItem["id"] . ' ,2);"><img src="../imagens/excluir.png" title="Excluir: '.$sItem["titulo"].'" border="0"></a></td>';
						echo '</tr>';
					}
					echo '</table>';
				}
				else
				{
					echo "Página vazia";
				}
				?>
          </div>
        </td>
    </tr>
  </table>
</body>
</html>